#ifndef MATERIALSHADEREDITORDIALOG_H
#define MATERIALSHADEREDITORDIALOG_H

#include <qdialog.h>
#include <ui_shadereditorwidget.h>
#include <material/materialmanager.h>
#include <material/materialeditor.h>
#include <qtimer.h>

class GLSLTextEditor;

class cceMaterialShaderBindingTreeModel : public QAbstractItemModel
{
  Q_OBJECT
private:
  cceMaterialShader *_shader;

  enum Column
  {
    Column_Type,
    Column_Variable,
    Column_Semantic,
    Column_COUNT
  };

  QColor    _backgroundColors [cceMaterialShader::BindingType_COUNT * 2];

private slots:
  void BindingsChanged ();

public:
  cceMaterialShaderBindingTreeModel (QObject* parent, cceMaterialShader *shader);

  virtual int columnCount(const QModelIndex &parent) const;
  virtual QVariant data (const QModelIndex &index, int role) const;
  virtual QModelIndex index (int row, int column, const QModelIndex &parent) const;
  virtual QModelIndex parent (const QModelIndex &child) const;
  virtual int rowCount(const QModelIndex &parent) const;
  virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;

};


class cceMaterialShaderEditorDialog : public cceMaterialEditorAbstract
{
  Q_OBJECT
private:
  Ui::MaterialShaderEditorWidget    _gui;

  cceMaterialShader                 *_proxyShader;
  cceMaterialShader                 *_shader;
  GLSLTextEditor                    *_textEditor;
  cceMaterialShaderBindingTreeModel *_bindingModel;

  QTimer                            _updateBindingTime;

private:
	bool UpdateShaderFromGUI();
  void UpdateGUIFromShader();

  bool ShaderChanged ();
	QString GetExtension () const;

private slots:
  void on_lineEditName_textChanged(const QString& text);
  void on_comboBoxType_currentIndexChanged (int index);

  void ForceClose ();

  void CodeChanged ();
  void UpdateBindings();


public:
  cceMaterialShaderEditorDialog(QWidget *parent = 0);
  ~cceMaterialShaderEditorDialog ();

  QString GetName() const;
  virtual bool Save ();

  void SetShader (cceMaterialShader* shader);

public slots:
  void Close ();

};

#endif // MATERIALSHADEREDITORDIALOG_H
